/*
 *  $Id: Name.cs 1185 2010-11-11 14:21:54Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2010 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System.Text;

using Nereal.Serialization;

namespace Ragima.Languages {
    /// <summary>
    /// Падежи русского языка.
    /// </summary>
    public enum RussianCase {
        Nominative,
        Genitive,
        Dative,
        Accusative,
        Ablative,
        Prepositional,
        Locative
    }

    /// <summary>
    /// Слово (имя) на русском языке во всех падежах.
    /// </summary>
    [ResourceLang("ru"), ConstructorParameters("Template", "LocativeIsDative")]
    public sealed class RussianName : LocalizedName {
        private const int NumCases = 6;

        private string _template;
        private string[] _names;
        private bool _locativeIsDative;

        public RussianName(string template) : this(template, false) {
        }
        public RussianName(string template, bool locative) {
            Template = template;
            _locativeIsDative = locative;
        }
        public RussianName(string n0, string n1, string n2, string n3, string n4, string n5) : this(n0, n1, n2, n3, n4, n5, false) {
        }
        public RussianName(string n0, string n1, string n2, string n3, string n4, string n5, bool locative) {
            Template = Helper.StringGrouper.Default.Group(new string[] { n0, n1, n2, n3, n4, n5 });
            _locativeIsDative = locative;
        }

        /// <summary>
        /// Шаблон имени.
        /// </summary>
        [XmlName("n")]
        public string Template {
            get { return _template; }
            set {
                _template = value;
                _names = Helper.StringGrouper.Default.Ungroup(value, NumCases);
            }
        }

        /// <summary>
        /// Имя в именительном падеже.
        /// </summary>
        public override string Nominative {
            get { return this[RussianCase.Nominative]; }
        }
        /// <summary>
        /// Имя в родительном падеже.
        /// </summary>
        public string Genitive {
            get { return this[RussianCase.Genitive]; }
        }
        /// <summary>
        /// Имя в дательном падеже.
        /// </summary>
        public string Dative {
            get { return this[RussianCase.Dative]; }
        }
        /// <summary>
        /// Имя в винительном падеже.
        /// </summary>
        public string Accusative {
            get { return this[RussianCase.Accusative]; }
        }
        /// <summary>
        /// Имя в творительном падеже.
        /// </summary>
        public string Ablative {
            get { return this[RussianCase.Ablative]; }
        }
        /// <summary>
        /// Имя в предложном падеже.
        /// </summary>
        public string Prepositional {
            get { return this[RussianCase.Prepositional]; }
        }
        /// <summary>
        /// Имя в местном падеже.
        /// </summary>
        public string Locative {
            get { return this[RussianCase.Locative]; }
        }

        /// <summary>
        /// Представлен ли местный падеж дательным.
        /// </summary>
        [XmlName("locative"), DefaultValue(false)]
        public bool LocativeIsDative {
            get { return _locativeIsDative; }
        }

        /// <summary>
        /// Падеж, представляющий местный.
        /// </summary>
        public RussianCase LocativeCase {
            get { return _locativeIsDative ? RussianCase.Dative : RussianCase.Prepositional; }
        }

        /// <summary>
        /// Имя по падежу.
        /// </summary>
        public string this[RussianCase c] {
            get {
                if (c == RussianCase.Locative)
                    c = LocativeCase;
                return _names[(int) c];
            }
        }

        /// <summary>
        /// Создает ресурс русского имени.
        /// </summary>
        public static ResourceItem New(string id, string template) { return new ResourceItem(id, new RussianName(template)); }
        /// <summary>
        /// Создает ресурс русского имени.
        /// </summary>
        public static ResourceItem New(string id, string template, bool locative) { return new ResourceItem(id, new RussianName(template, locative)); }
        /// <summary>
        /// Создает ресурс русского имени.
        /// </summary>
        public static ResourceItem New(string id, string n0, string n1, string n2, string n3, string n4, string n5) { return new ResourceItem(id, new RussianName(n0, n1, n2, n3, n4, n5)); }
        /// <summary>
        /// Создает ресурс русского имени.
        /// </summary>
        public static ResourceItem New(string id, string n0, string n1, string n2, string n3, string n4, string n5, bool locative) { return new ResourceItem(id, new RussianName(n0, n1, n2, n3, n4, n5, locative)); }
    }
}
